package HLLib.ui;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLObject;
import HLLib.base.HLGraphics;
import HLLib.base.HLRectangle;
import HLLib.io.HLFile;

public class HLUIControlLine extends HLUIControl {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_UI, HLClassManager_H.LIB_CLASS_UI_UIControlLine);
    }

    public int GetInt(int index) {
        switch (index) {
        case 1: {
            return color;
        }
        case 2: {
            return linePosStyle;
        }
        }
        return super.GetInt(index);
    }

    public void SetInt(int index, int value) {
        switch (index) {
        case 1: {
            color = value;
            return;
        }
        case 2: {
            linePosStyle = (byte) value;
            return;
        }
        }
        super.SetInt(index, value);
    }

    public boolean GetBoolean(int index) {
        return super.GetBoolean(index);
    }

    public void SetBoolean(int index, boolean value) {
        super.SetBoolean(index, value);
    }

    public HLObject GetObject(int index) {
        return super.GetObject(index);
    }

    public void SetObject(int index, HLObject value) {
        super.SetObject(index, value);
    }

    public int color;

    public byte linePosStyle;

    public HLUIControlLine() {
    }

    HLUIControlLine(HLUIFrame ownerFrame) {
        super(ownerFrame);
    }

    void Load(HLFile file) {
        super.Load(file);
        byte a = file.ReadInt8();
        byte r = file.ReadInt8();
        byte g = file.ReadInt8();
        byte b = file.ReadInt8();
        color = HLGraphics.ARGB(a, r, g, b);
        linePosStyle = file.ReadInt8();
    }

    void Render(HLGraphics g, int rectX, int rectY, int rectWidth, int rectHeight, int color) {
        HLRectangle area = GetArea(rectX, rectY, rectWidth, rectHeight);
        color = HLGraphics.ColorMultiply(color, this.color);
        switch (linePosStyle) {
        case LEFT: {
            g.FillRectAlpha(area.x, area.y, 1, area.height, color);
            break;
        }
        case HCENTER: {
            g.FillRectAlpha((area.x + area.GetRight() - 1) / 2, area.y, 1, area.height, color);
            break;
        }
        case RIGHT: {
            g.FillRectAlpha(area.GetRight() - 1, area.y, 1, area.height, color);
            break;
        }
        case TOP: {
            g.FillRectAlpha(area.x, area.y, area.width, 1, color);
            break;
        }
        case VCENTER: {
            g.FillRectAlpha(area.x, (area.y + area.GetBottom() - 1) / 2, area.width, 1, color);
            break;
        }
        case BOTTOM: {
            g.FillRectAlpha(area.x, area.GetBottom() - 1, area.width, 1, color);
            break;
        }
        }
    }

    void CopyFrom(HLUIControl uiControl) {
        super.CopyFrom(uiControl);

        HLUIControlLine uiControlByType = (HLUIControlLine) uiControl;

        color = uiControlByType.color;

        linePosStyle = uiControlByType.linePosStyle;
    }

    HLUIControl Clone(HLUIFrame ownerFrame) {
        HLUIControlLine uiControl = new HLUIControlLine();
        uiControl.ownerFrame = ownerFrame;
        uiControl.CopyFrom(this);
        return uiControl;
    }
}
